package com.hll.api.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hll.api.entity.Theme;
import com.hll.api.mapper.ThemeMapper;
import com.hll.api.service.IThemeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 主题 服务实现类
 * </p>
 *
 * @author 何龙
 * @since 2019-07-18
 */
@Service
public class ThemeServiceImpl extends ServiceImpl<ThemeMapper, Theme> implements IThemeService {

	final ThemeMapper mapper;

	public ThemeServiceImpl(ThemeMapper mapper) {this.mapper = mapper;}

	@Override
	public boolean mySave(Theme theme) {
		Integer integer = mapper.selectCount(null);
		if (integer==0){
			theme.setIsDefault(true);
		}
		return mapper.insert(theme)>0;
	}

	@Override
	public boolean setTheme(Theme theme) {
		theme.setIsDefault(true);
		mapper.updateById(theme);
		mapper.updateThemeById(theme.getId());
		return true;
	}
}
